

import 'package:bt_tool/basic/bt_common_define.dart';
import 'package:bt_tool/basic/bt_controller.dart';
import 'package:bt_tool/widget/bt_base_btn_widget.dart';
import 'package:bt_tool/widget/bt_check_box.dart';
import 'package:bt_tool/widget/bt_text_field.dart';
import 'package:bt_tool/widget/bt_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/common/config/app_theme_color_config.dart';
import 'package:flutter_demo/tools/json/json_main_controller.dart';
import 'package:get/get.dart';

class JsonMainPage extends BTStatefulWidget{

  const JsonMainPage({super.key,super.routerConfig});

  @override
  State<StatefulWidget> createState() {
    return JsonMainPageState();
  }

}


class JsonMainPageState extends BTState<JsonMainPage>{

  final JsonMainController ctl = JsonMainController();

  @override
  BTController btCtrl() {
    return ctl;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints.expand(),
      padding: const EdgeInsets.all(10),
      color: AppThemeColor.contentBgColor,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text("json内容"),
          const SizedBox(height: 10,),
          Expanded(child: Container(
            constraints: const BoxConstraints.expand(),
            child: BTTextFieldWidget(
              btTextFieldController: ctl.inputCtl,
              maxLine: BTTextFieldWidget.maxLineDefine,
              isIgnoreClearBtn: true,
            ),
          )),
          const SizedBox(height: 10,),
          Row(
            children: [
              const Text("模型结果"),
              const SizedBox(width: 10,),
              Expanded(
                child: Obx((){
                  ListView listView = ListView.builder(
                    scrollDirection:  Axis.horizontal,
                    itemCount: ctl.resultList.length,
                    itemBuilder: (c,i){
                      return GestureDetector(
                        onTap: (){
                          ctl.changeIndex(i);
                        },
                        child: Container(
                          alignment: Alignment.centerLeft,
                          padding: const EdgeInsets.only(right: 20),
                          child: Obx(()=>Text(
                            ctl.resultList[i].getDisplayFileName(),
                            style: TextStyle(
                              color: ctl.selectFileIndex.value == i ? AppThemeColor.mainColor : AppThemeColor.textColor,
                            ),
                          )),
                        ),
                      );
                    },
                  );
                  return SizedBox(
                    height: 40,
                    child: listView,
                  );
                }),
              )
            ],
          ),
          Expanded(child: Container(
            constraints: const BoxConstraints.expand(),
            child: BTTextFieldWidget(
              btTextFieldController: ctl.resultCtl,
              maxLine: BTTextFieldWidget.maxLineDefine,
              isIgnoreClearBtn: true,
            ),
          )),
          const SizedBox(height: 10,),
          Row(
            children: [
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text("基本类名称:"),
                    const SizedBox(height: 10,),
                    Container(
                      constraints: const BoxConstraints.expand(width: 200,height: 35),
                      child: BTTextFieldWidget(
                        btTextFieldController: ctl.baseCtl,
                        bgCornerRadius: 4,
                        textFieldPadding: const EdgeInsets.fromLTRB(12, 2, 0, 0),
                        hintText: "例如：Chat",
                        hintStyle: const TextStyle(color: Colors.grey,fontSize: 14),
                      ),
                    )
                  ],
                ),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text("转换类型:"),
                    const SizedBox(height: 10,),
                    Container(
                      constraints: const BoxConstraints.expand(height: 35),
                      child: Align(
                        alignment: Alignment.centerLeft,
                        child: Obx(()=> BTCheckBoxGroup(
                          titleArray: const ["flutter","objectC","swift","swift-oc"],
                          clickCallback: (i){
                            ctl.jsonType.value = ToolsJsonType.fromInt(i);
                          },
                          selectIndex: ctl.jsonType.value.iValue,
                          selectImg: Image.asset(btPngPath("bt/bt_check_box_sel")),
                          normalImg: Image.asset(btPngPath("bt/bt_check_box_nor")),
                        )),
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
          const SizedBox(height: 10,),
          SizedBox(
            height: 50,
            child: Row(
              children: [
                BTBtnTextWidget(
                  bgColor: AppThemeColor.mainColor,
                  constraints: const BoxConstraints.expand(width: 100,height: 40),
                  text: "转换",
                  textColor: Colors.white,
                  onTap: () => ctl.convert(),
                  alignment: Alignment.center,
                ),
                const SizedBox(width: 10,),
                BTBtnTextWidget(
                  bgColor: AppThemeColor.mainColor,
                  constraints: const BoxConstraints.expand(width: 100,height: 40),
                  text: "测试实例",
                  textColor: Colors.white,
                  onTap: () => ctl.defaultTest(),
                  alignment: Alignment.center,
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

}


